import { reqCategory1List, reqCategory2List, reqCategory3List } from '@/api/category'
const state = {
    category1id: '',
    category2id: '',
    category3id: '',
    category1list: [],
    category2list: [],
    category3list: [],
}
const mutations = {
    StoresetCategory1List(state, payload) {
        state.category1list = payload
    },
    StoresetCategory2List(state, payload) {
        // 重新选择数据时应该清除后面的历史数据
        state.category2id = ''
        state.category3id = ''
        state.category3list = []
        state.category2list = payload
    },
    StoresetCategory3List(state, payload) {
        state.category3id = ''
        state.category3list = payload
    }
}
const actions = {
    async StoregetCategory1List({ commit }) {
        let re = await reqCategory1List()
        commit('StoresetCategory1List', re)
    },
    async StoregetCategory2List({ state, commit }) {
        let re = await reqCategory2List(state.category1id)
        commit('StoresetCategory2List', re)
    },
    async StoregetCategory3List({ state, commit }) {
        let re = await reqCategory3List(state.category2id)
        commit('StoresetCategory3List', re)
    }
}
export default {
    namespaced: true,
    state,
    actions,
    mutations
}
